/**
 * @file
 * @author Filipe Mutz
 *
 * @section DESCRIPTION
 *
 */
#include "receptive_field.h"

namespace brain
{
	namespace receptive_field
	{
		VisualReceptiveField::VisualReceptiveField()
		{
		}


		VisualReceptiveField::~VisualReceptiveField()
		{
		}


		int
		VisualReceptiveField::compare_pixels(GrayscaleImage *img, Point &point, Gray &gray)
		{
			Gray point_gray_intensity = img->get(point[0], point[1]);

			if (point_gray_intensity.intensity >= gray.intensity)
				return 1;
			else
				return 0;
		}


		vector<int>
		VisualReceptiveField::generate_neuron_input(pair<GrayscaleImage*, vector<Point>* > stimulus)
		{
			int pattern_int_position;
			vector<int> pattern;

			GrayscaleImage *img = stimulus.first;
			vector<Point> *distribution = stimulus.second;

			int distribution_size = distribution->size();
			int num_bits_per_int = sizeof(int) * 8;

			Gray center = img->get(distribution->at(0)[0], distribution->at(0)[1]);

			for(int i = 1; i < distribution_size; i++)
			{
				pattern_int_position = i / num_bits_per_int;

				if (pattern_int_position >= (int) pattern.size())
					pattern.push_back(0);

				pattern[pattern_int_position] = pattern[pattern_int_position] << 1;
				pattern[pattern_int_position] += compare_pixels(img, distribution->at(i), center);
			}

			return pattern;
		}
	}
}


